package demo1;

import demo2.Cell;

import java.awt.*;

public class Draw {
    static Statement se=new Statement();
    //绘制游戏当前状态
    public static void paintState(Graphics g) {
        if(Statement.game_state == Statement.PLAYING){
            g.drawString(se.show_state[0],500,660);
        }else if(Statement.game_state == Statement.PAUSE){
            g.drawString(se.show_state[1],500,660);
        }else if(Statement.game_state == Statement.GAMEOVER){
            g.drawString(se.show_state[2],500,660);
            g.setColor(Color.red);
            g.setFont(new Font(Font.SANS_SERIF, Font.BOLD,60));
            g.drawString("GAME OVER!", 30, 400);
        }
    }

    //绘制游戏得分
    public static void paintScore(Graphics g) {
        g.setFont(new Font(Font.SANS_SERIF, Font.BOLD,30));
        g.drawString("SCORES: " + Statement.totalScore, 500, 248);
        g.drawString("LINES: " + Statement.totalLine, 500, 430);
    }

    //绘制下一个将要下落的四方格
    public static void paintNextOne(Graphics g) {
        Cell[] cells = Statement.nextOne.cells;
        for (Cell cell : cells) {
            int x = cell.getCol() * Statement.CELL_SIZE + 370;
            int y = cell.getRow() * Statement.CELL_SIZE + 25;
            g.drawImage(cell.getImage(), x, y, null);
        }
    }

    //绘制正在下落的四方格
    public static void paintCurrentOne(Graphics g) {
        Cell[] cells = Statement.currentOne.cells;
        for (Cell cell : cells) {
            int x = cell.getCol() * Statement.CELL_SIZE;
            int y = cell.getRow() * Statement.CELL_SIZE;
            g.drawImage(cell.getImage(), x, y, null);
        }
    }

    //绘制游戏主区域
    public static void paintWall(Graphics g) {
        for(int i = 0; i < Statement.wall.length; i++){
            for(int j = 0; j < Statement.wall[i].length; j++){
                int x = j * Statement.CELL_SIZE;
                int y = i * Statement.CELL_SIZE;
                Cell cell = Statement.wall[i][j];
                //判断当前单元格是否有小方块，如果没有则绘制矩形，否则将小方块嵌入到墙中
                if(cell == null){
                    g.drawRect(x, y, Statement.CELL_SIZE, Statement.CELL_SIZE);
                }else{
                    g.drawImage(cell.getImage(), x, y, null);
                }
            }
        }
    }
}
